package cn.gson.crm.controller.dept;

import java.util.List;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.DeptDao;
import cn.gson.crm.model.entity.Dept;

/**
 * 部门管理界面
 */
@WebServlet("/dept")
public class DeptManagerServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private DeptDao deptDao = new DeptDao();

	@Override
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {

		String deptName = request.getParameter("deptName");
		String deptManager = request.getParameter("deptManager");
		String p = request.getParameter("page");
		if (p == null || p.isEmpty()) {
			p = "1";
		}
		Integer page = Integer.parseInt(p);
		List<Dept> deptList = deptDao.getDeptList(deptName, deptManager, 1, page);
		Integer totalPage = deptDao.getTotalPage(1, deptName, deptManager);
		request.setAttribute("page", page);
		request.setAttribute("queryString", noPageQueryString(request));
		request.setAttribute("totalPage", totalPage);
		request.setAttribute("deptList", deptList);
			setReqAndRemoveRes("cantBeDeleDeptList",request,"cantBeDeleDeptList");
			setReqAndRemoveRes("deleErro",request,"deleErro");
		getServletPathAndForward(request, "dept/manage.jsp");
//		forward("/dept/manage.jsp");
	}
}
